from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options

# 设置 Chrome 无头模式
chrome_options = Options()
chrome_options.add_argument("--headless")  # 启用无头模式
chrome_options.add_argument("--disable-gpu")  # 禁用 GPU 加速

# 创建 WebDriver 实例
driver = webdriver.Chrome(service=Service('D:\Downloads\chromedriver-win64\chromedriver-win64\chromedriver.exe'), options=chrome_options)

# 打开网页
driver.get("https://www.baidu.com")

# 打印网页标题
print(driver.title)

# 关闭浏览器
driver.quit()